<?php
function view_div($file,$image,$name,$is_dir){  
	if($is_dir){ 
		$onclick = "enterIn('".$file."')";
	}else {
		$onclick = "choosed_file('".$file."')";
	}
	
	$html = "<div style='float:left;width:150px;height:auto;overflow:hidden;margin:5px;border:1px solid #bebebe;'>";
	$html .= "<a href='javascript:void(0)' onclick=\"".$onclick."\" ><div style='height:150px;overflow:hidden;margin:5px;'>
				<img src='".$image."' style='max-width:145px;max-height:150px;'/>
			  </div></a>";
	$html .= "<div style='height:30px;line-height:30px;overflow:hidden;border-bottom:1px solid #bebebe;
				border-top:1px solid #bebebe;text-align:center;'><a href='javascript:void(0)' onclick=\"".$onclick."\" style='padding:5px;'>".$name."</a></div>";
	
	if($name != '上级目录'){
		$html .= "
				<div style='padding:5px;text-align:center;'>
					<a href='javascript:void(0)' onclick='editFile(this,1)'>[重命名]</a>
					<a href='javascript:void(0)' onclick='deleteFile(this,1)'>[删除]</a>
				</div>
				";
	}
	$html .= "</div>";
	
	return $html; 
}

$html = "";
$html .= "<TABLE class='table_list' width='100%' cellspacing='0' cellpadding='0'><tr><td><div style='overflow:auto;overflow-x:hidden;height:322px;width:100%'>" ;


if($root != $currentPath){
	$file = to_php_encoding(dirname($currentPath).'/');
	$html .= view_div($file,'./icons/folder_view.jpg','上级目录',true); 
}

$order = deep_get('order',0,1);

$folders = find_folders($currentPath);
$folders = order_list($folders,$order,$currentPath);
if(!empty($folders)){
	for($i=0;$i<count($folders);$i++){
		$folder = $folders[$i];
		$file = to_php_encoding($currentPath.$folder.'/');
		$html .= view_div($file,'./icons/folder_view.jpg',$folder,true); 
	}
}

$files = find_files($currentPath,$accept_types,false);
$files = order_list($files,$order);

if(!empty($files)){
	for($i=0;$i<count($files);$i++){
		$file = $files[$i]; 
		$base_name = get_base_name($file);
		$file_name = to_php_encoding($base_name) ;
		$relative_path = $src_path . to_linux_path(str_replace($root,"",$file)); 
		
		$icon = "/p5/explorer/icons/unknowFile.gif";
		if(file_exists($icon_file)){
			$icon = "/p5/explorer/icons/".$file_type.".gif";
		}
		
		$file = to_php_encoding($currentPath.$folder.'/');
		$html .= view_div($relative_path,$relative_path,$file_name,false); 
	}
}

$html .= "</div></td></tr></TABLE>";
print $html;